package com.hnn;

import java.io.File;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * @author hnn
 * @version 1.0
 * @date 2023-12-05 13:50
 */
public class TestFile {
    public static void main(String[] args) {

        try {
            String fileName = "d.zip";
            String ossKey = "vpn/rsa/" + fileName;
            //本地文件路径
            File localFile = new File("/data/cloudpark/rsa/" + fileName);

            if (localFile.exists()) {
                localFile.delete();
            }
            if (!localFile.getParentFile().exists()) {
                localFile.getParentFile().mkdir();
            }

            Process p1 = Runtime.getRuntime().exec(new String[]{
                    "sh",
                    "createVpnCert.sh",
                    "reformer-raven@192.168.250.4",
                    "aa",
                    "aa",
                    "/data/reformer-raven/rsa/"
            });

            if (!p1.waitFor(4, TimeUnit.SECONDS)|| !localFile.exists()) {
            }

            try (InputStreamReader ir = new InputStreamReader(p1.getInputStream())) {
                char[] b = new char[1024];
                int len = ir.read(b);
                System.out.println(new String(Arrays.copyOfRange(b, 0, len)));
            }
        } catch (Exception e) {
            System.out.println("生成证书异常");
            System.out.println(e);
        }
    }
}
